﻿Imports NVelocity
Imports NVelocity.App
Imports NVelocity.Context

Imports System.Collections.Generic
Imports System.IO
Imports System.Globalization
Imports System.Data
Imports System.Transactions
Partial Class WebForm_SearchHonorCert
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            RaiseEvent Loaded(Me, New EventArgs)

        End If

        ScriptManager.GetCurrent(Me.Page).RegisterPostBackControl(Me.btnHonorCertExport)
        ScriptManager.GetCurrent(Me.Page).RegisterPostBackControl(Me.btnImport)
        Me.phUpload.Visible = Me.IsVisible
    End Sub

    Protected Sub gv_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv.DataBinding
        '    Me.gv.Columns(3).HeaderText = (Year(DateTime.Now) - 1911) & Me.GetLocalResourceObject("bfStop")
        '    Me.gv.Columns(4).HeaderText = (Year(DateTime.Now) - 1911 - 1) & Me.GetLocalResourceObject("bfStop")
        '    Me.gv.Columns(5).HeaderText = (Year(DateTime.Now) - 1911 - 2) & Me.GetLocalResourceObject("bfStop")
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub

    Protected Sub gv_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv.SelectedIndexChanged
        RaiseEvent SelectedIndexChanged(Me, New EventArgs)
    End Sub


    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub

    Protected Sub gv_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gv.Sorting
        Me.BindGV()
    End Sub

    Protected Sub gv_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv.DataBound
        '有資料才可匯出榮譽卡申請名冊
        If Me.gv.Rows.Count > 0 Then
            Me.btnHonorCertExport.Enabled = True
        Else
            Me.btnHonorCertExport.Enabled = False
        End If
    End Sub

    Protected Sub btnHonorCertExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHonorCertExport.Click
        Me.PrintHonerCertList()
    End Sub

    Protected Sub gv_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gv.RowCancelingEdit
        If Me.CancelHonortCert(e.RowIndex) = True Then
            Me.BindGV()
        End If
    End Sub

    Protected Sub btnImport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnImport.Click
        If SaveImportData() Then
            MyObj.ShowMessage("匯入成功!")
        End If
    End Sub
End Class


Partial Class WebForm_SearchHonorCert

    Private Function SaveImportData() As Boolean
        If Not fileupload1.HasFile Then
            MyObj.ShowMessage("no file")
            Return False
        ElseIf fileupload1.PostedFile.ContentType.ToString() <> "application/vnd.ms-excel" AndAlso fileupload1.PostedFile.ContentType.ToString() <> "application/octet-stream" Then
            MyObj.ShowMessage("匯入失敗!!請選擇副檔名(xls、csv)檔案!!")
            Return False
        End If
        Me.gvError.Visible = False
        '上傳暫存檔
        Dim clsRandom As New clsRandom()
        Dim newName As String = Server.MapPath("~/") & "/tmp/" & clsRandom.Generate()
        fileupload1.PostedFile.SaveAs(newName)

        Dim ExcelImportCheck As New ExcelImportCheck()
        Dim dt As New DataTable
        Dim ColumnList As String(,) = {{"姓名", "N"}, {"身份證字號", "N"}, {"榮譽卡號碼", "N"}, {"申請日期", "N"}, {"核發日期", "N"}, {"有效期限", "N"}, {"榮譽卡類別", "N"}}

        '檢查工作表名稱
        If ExcelImportCheck.LoadData(dt, newName, "匯入榮譽卡名單") = False Then
            Return False
        End If
        For j As Integer = 0 To dt.Columns.Count - 1

            dt.Columns(j).ColumnName = dt.Columns(j).ColumnName.Trim()

        Next

        '濾掉空白資料
        Dim FilterValue As String = ""
        For k As Integer = 0 To (ColumnList.Length / 2) - 1
            If FilterValue = "" Then
                FilterValue &= "[" & ColumnList(k, 0) & "]<>''"
            Else
                FilterValue &= " or [" & ColumnList(k, 0) & "]<>''"
            End If
        Next
        Dim MyDefaultView As Data.DataView = dt.DefaultView
        MyDefaultView.RowFilter = FilterValue
        dt = MyDefaultView.ToTable()
        Dim colString As DataColumn = New DataColumn("檢查結果")
        colString.DataType = System.Type.GetType("System.String")
        dt.Columns.Add(colString)
        Dim EndString As String = ""
        Dim ErrorCount As Integer = 0
        For i As Integer = 0 To dt.Rows.Count - 1
            dt.Rows(i)("檢查結果") = ""

            'dt.DefaultView.RowFilter = String.Format("[身份證字號] = '{0}' ", getVolunteerData.Rows(i)("VolunteerID").ToString())

            If Me.getVolunteerData(dt.Rows(i)("身份證字號").ToString()) = False Then
                dt.Rows(i)("檢查結果") &= "身份證字號" & dt.Rows(i)("身份證字號").ToString() & "不存在於系統中,"
                ErrorCount = ErrorCount + 1
                'Else
                '    EndString &= dt.Rows(i)("身份證字號").ToString() & ","
            End If

            Try
                dt.Rows(i)("核發日期") = Convert.ToDateTime(dt.Rows(i)("核發日期").ToString())
            Catch ex As System.FormatException
                dt.Rows(i)("檢查結果") &= dt.Rows(i)("身份證字號").ToString() & "核發日期有誤,"
                ErrorCount = ErrorCount + 1
            End Try

            Try
                dt.Rows(i)("有效期限") = Convert.ToDateTime(dt.Rows(i)("有效期限").ToString())
            Catch ex As System.FormatException
                dt.Rows(i)("檢查結果") &= dt.Rows(i)("身份證字號").ToString() & "有效期限有誤,"
                ErrorCount = ErrorCount + 1
            End Try
            Try
                dt.Rows(i)("申請日期") = Convert.ToDateTime(dt.Rows(i)("申請日期").ToString())
            Catch ex As System.FormatException
                dt.Rows(i)("檢查結果") &= dt.Rows(i)("身份證字號").ToString() & "申請日期有誤,"
                ErrorCount = ErrorCount + 1
            End Try


        Next

        If ErrorCount > 0 Then
            Me.gvError.Visible = True
            Me.gvError.DataSource = dt
            Me.gvError.DataBind()
            'MyObj.WriteErrorLog(EndString)
            MyObj.ShowMessage("匯入失敗")
            ' MyObj.ExportToExcel(gvError, "HList.xls")
            Return False
        Else

            Dim sql As New MyStringBuilder
            Dim dat As New clsData
            Using scope As New Transactions.TransactionScope(TransactionScopeOption.Required, New TimeSpan(2, 0, 0))

                For i As Integer = 0 To dt.Rows.Count - 1

                    sql.Length = 0
                    sql.AppendFormat("insert into HonorCert (VolunteerID,HonorCertCode,IssueDate,EndDate,CreateDate,CreateBy,Active,ApplyDate,Type) select ")
                    sql.AppendFormat("'{0}' ", dt.Rows(i)("身份證字號").ToString())
                    sql.AppendFormat(",'{0}' ", dt.Rows(i)("榮譽卡號碼").ToString())
                    sql.AppendFormat(",'{0:yyyy/MM/dd}' ", Convert.ToDateTime(dt.Rows(i)("核發日期").ToString()))
                    sql.AppendFormat(",'{0:yyyy/MM/dd}' ", Convert.ToDateTime(dt.Rows(i)("有效期限").ToString()))
                    sql.AppendFormat(",{0} ", "getdate()")
                    sql.AppendFormat(",'{0}' ", clsAuth.GetUserID())
                    sql.AppendFormat(",'{0}' ", "Y")
                    sql.AppendFormat(",'{0:yyyy/MM/dd}' ", Convert.ToDateTime(dt.Rows(i)("申請日期").ToString()))
                    sql.AppendFormat(",(select value from CodeMapping where TableName='HonorCert' and ColumnName='Type' and Text='{0}') ", dt.Rows(i)("榮譽卡類別").ToString())
                    sql.AppendFormat("where '{0}' not in (Select VolunteerID from HonorCert where  EndDate>getdate()); ", dt.Rows(i)("身份證字號").ToString())


                    sql.AppendFormat("Insert Into HonorCertApplication (VolunteerID,CreateDate,CreateBy,Status,WorkHour) ")
                    sql.AppendFormat("select '{0}',getdate(),'{1}','AP' ", dt.Rows(i)("身份證字號").ToString(), clsAuth.GetUserID())
                    sql.AppendFormat(",'0'  ")
                    sql.AppendFormat("where '{0}' not in (Select VolunteerID from HonorCertApplication where Status='WA'); ", dt.Rows(i)("身份證字號").ToString())

                    sql.AppendFormat("update HonorCertApplication set  ")
                    sql.AppendFormat("WorkHour= isnull(vs.WorkHour,0) from (Select  sum(WorkHour) as WorkHour,volunteerID from VWorkHourYYMM  ")
                    sql.AppendFormat("where VolunteerID='{0}' and cast(yymm as integer) <'{1}' group by volunteerID) vs ", dt.Rows(i)("身份證字號").ToString(), Int32.Parse(dt.Rows(i)("申請日期").ToString().Split(".")(0)) + 1911 & dt.Rows(i)("申請日期").ToString().Split(".")(1))
                    sql.AppendFormat(" where HonorCertApplication.VolunteerID='{0}' AND Status in ('AP','WA'); ", dt.Rows(i)("身份證字號").ToString())
                    dat.AccData(sql)

                Next

                scope.Complete()
                Return True
            End Using
        End If
    End Function

    Public Sub BindGV()
        Me.gv.Columns(6).Visible = Me.IsVisible
        Me.gv.Columns(7).Visible = Me.IsVisible
        Me.gv.DataSource = Me.GetHonorCertList()
        Me.gv.DataBind()
    End Sub
    Private Function getVolunteerData(ByVal VolunteerID As String) As Boolean
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        sql.Length = 0
        sql.AppendFormat("select VolunteerID from Volunteer ")
        sql.AppendFormat("where VolunteerID ='{0}' ", VolunteerID)
        Return dat.GetData(sql).Rows.Count > 0
    End Function
    Private Function GetHonorCertList() As System.Data.DataTable
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat(" Select  v.VolunteerID, v.Volunteername,vs.WorkHour, hca.CreateDate,hca.ApplicationID, ApplyWorkHour = vs.HornorHour ")
        sql.AppendFormat(", vb.VBookID, v.PhotoPath, v.Birthday, VBookIssueDate = vb.IssueDate,oo.VOrganizationName,org.OrganizationName,hc.EndDate ")
        sql.AppendFormat(" from HonorCertApplication hca ")
        sql.AppendFormat(" left join HonorCert hc on hc.VolunteerID=hca.VolunteerID ")
        sql.AppendFormat(" inner join Volunteer v on hca.VolunteerID = v.VolunteerID ")
        sql.AppendFormat(" inner join VolunteerStatV2 vs on v.VolunteerID = vs.VolunteerID ")
        sql.AppendFormat(" inner join VBookView vb on v.VolunteerID = vb.VolunteerID and vb.Active = 'Y' ")
        sql.AppendFormat("  left JOIN (select vm.VOrganizationID,vo.VOrganizationName,vm.VolunteerID,vo.DirectUOrganizationID from VOrganizationMapping vm ")
        sql.AppendFormat("inner join VOrganizationViewV2 vo on vm.VOrganizationID=vo.VOrganizationID ) oo on v.VolunteerID=oo.VolunteerID  ")
        sql.AppendFormat("left join  OrganizationView org on oo.DirectUOrganizationID=org.UOrganizationID ")


        sql.AppendFormat(" where hca.Status in ('WA') ")
        sql.AppendFormat(GetWhereSQL())
    
        sql.AppendFormat("ORDER BY org.OrganizationName ")

        'MyObj.WriteErrorLog(sql.ToString())
        Return dat.GetData(sql)
    End Function

    Private Sub BindGV2(ByVal gv As GridView)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat(" select v.* ")
        sql.AppendFormat(",Case v.Gender when 'F' then '女' else '男' end vGender ")
        sql.AppendFormat(GetDate("v.Birthday", "vBirthday"))
        sql.AppendFormat(",R1.RegionName")
        sql.AppendFormat(",2 as VBookTypeID, '050' as SerialGroupID")
        sql.AppendFormat(",'' as Picture,'V' as GetVBook,'' as ChangeVBook ")
        sql.AppendFormat(GetDate("tgb.StartDate", "tgbStartDate"))
        sql.AppendFormat(", tgb.Org as trbOrg, tgs.Org as trsOrg ")
        sql.AppendFormat(GetDate("tgs.StartDate", "tgsStartDate"))
        sql.AppendFormat(" from VolunteerDistinctView v ")
        sql.AppendFormat(" inner join VolunteerStat vs on v.VolunteerID = vs.VolunteerID ")
        sql.AppendFormat(" inner join VBookParameter VP on vs.TrainingBHour>=VP.BasicTrainingHour ")
        sql.AppendFormat(" and vs.TrainingSHour>=VP.SpecialTrainingHour ")
        sql.AppendFormat(" and vs.TrainingWHour>=VP.WorkTrainingHour ")
        sql.AppendFormat(" Left join Region R1 on v.VillageID = R1.RegionID ")
        sql.AppendFormat(" inner join trainingregister trb on v.VolunteerID = trb.VolunteerID ")
        sql.AppendFormat(" inner join trainingcoursegroup tgb on trb.GroupID = tgb.ID and tgb.GroupType='B' ")
        sql.AppendFormat(" inner join trainingregister trs on v.VolunteerID = trs.VolunteerID ")
        sql.AppendFormat(" inner join trainingcoursegroup tgs on trs.GroupID = tgs.ID and tgs.GroupType='S' ")
        sql.AppendFormat("  left JOIN (select vm.VOrganizationID,vo.VOrganizationName,vm.VolunteerID,vo.DirectUOrganizationID from VOrganizationMapping vm ")
        sql.AppendFormat("inner join VOrganizationViewV2 vo on vm.VOrganizationID=vo.VOrganizationID ) oo on v.VolunteerID=oo.VolunteerID  ")


        sql.AppendFormat(" where v.Active = '{0}' ", My.VolunteerStatus.Approved.ToString())
        sql.AppendFormat(GetWhereSQL())

        dt = dat.GetData(sql)
        gv.DataSource = dt
        gv.DataBind()
    End Sub



    Private Function GetWhereSQL() As String
        Dim sql As New MyStringBuilder

        If Me.VolunteerQueryControl1.OrganizationID <> "0" Then
            sql.AppendFormat("and (oo.DirectUOrganizationID = '{0}'  ) ", Me.VolunteerQueryControl1.OrganizationID)
            If Me.VolunteerQueryControl1.VOrganizationID <> "0" Then
                sql.AppendFormat("AND (oo.VOrganizationID = {0} ) ", Me.VolunteerQueryControl1.VOrganizationID)
            End If
        End If

        If Me.VolunteerQueryControl1.VolunteerName <> "" Then
            sql.AppendFormat("and v.Volunteername like '%{0}%' ", Me.VolunteerQueryControl1.VolunteerName)
        End If

        If Me.VolunteerQueryControl1.VolunteerId <> "" Then
            sql.AppendFormat("and v.VolunteerID = '{0}' ", Me.VolunteerQueryControl1.VolunteerId)
        End If

        sql.AppendFormat("and vs.HornorHour >={0} ", MyObj.GetParameter("HonorCert", "ApplyWorkHour"))

        Return sql.ToString()
    End Function

    Private Function GetDate(ByVal oldName As String, ByVal newName As String) As String
        Dim sql As New MyStringBuilder

        sql.AppendFormat(",Case " + oldName + " when null then null ")
        sql.AppendFormat(" else Cast((Year(" + oldName + ")-1911) as varchar)+'.' ")
        sql.AppendFormat(" +Right('0'+Cast(month(" + oldName + ") as varchar),2)+'.' ")
        sql.AppendFormat(" +Right('0'+Cast(day(" + oldName + ") as varchar),2) end " + newName + " ")

        Return sql.ToString()
    End Function

    Public ReadOnly Property SelectedVolunteerID() As String
        Get
            If Me.gv.SelectedRow Is Nothing Then
                Return Me.gv.Rows(0).Cells(0).Text
            Else
                Return Me.gv.SelectedRow.Cells(0).Text
            End If
        End Get
    End Property

    Private Sub PrintHonerCertList()
        Dim vcList As New List(Of HonerCertList)
        Dim vc As New HonerCertList
        Dim dt As System.Data.DataTable
        Dim base As Integer = 5
        Dim i As Integer = 0
        Dim RowCount As Integer = 1
        Dim prevVOrganizationName As String
        dt = Me.GetHonorCertList()


        For Each dr As Data.DataRow In dt.Rows

            If prevVOrganizationName <> "" AndAlso prevVOrganizationName <> dr("OrganizationName") Then

                If i Mod base <> 0 Then


                    For j As Integer = i Mod base To base - 1
                        i = i + 1
                        vc = New HonerCertList
                        vc.No = i.ToString("00")

                        vc.PhotoPath = ""
                        vc.Birthday = ""
                        vc.VOrganizationName = ""
                        vc.VolunteerName = ""
                        vc.VBookID = ""
                        vc.VolunteerID = ""
                        vc.WorkTotalHour = ""
                        vc.WorkStartDate = "  年  月  日"
                        vc.WorkEndDate = "  年  月  日"
                        ' vc.Index = i
                        vcList.Add(vc)

                        'i = i + 1
                    Next

                End If
                RowCount = 1
                i = 0
            End If

            vc = New HonerCertList
            i = i + 1
            vc.No = i.ToString("00")
            If Not TypeOf dr("PhotoPath") Is DBNull Then
                vc.PhotoPath = Me.GetPhoto(dr("PhotoPath").ToString())
            Else
                vc.PhotoPath = ""
            End If

            If Not TypeOf dr("OrganizationName") Is DBNull Then
                vc.VOrganizationName = dr("OrganizationName").ToString() & Space(1)

            Else
                vc.VOrganizationName = ""
            End If

            If vc.VOrganizationName.Length > 6 Then
                vc.VSpace = Space(29)
            Else

                vc.VSpace = Space(35)
            End If
            vc.VolunteerName = dr("VolunteerName").ToString()
            If Not TypeOf dr("Birthday") Is DBNull Then
                vc.Birthday = Convert.ToDateTime(dr("Birthday")).ToString("yyyy.MM.dd")
            Else
                vc.Birthday = ""
            End If
            If Not TypeOf dr("VBookIssueDate") Is DBNull Then
                vc.WorkStartDate = dr("VBookIssueDate").ToString.Split(".")(0) & "年" & dr("VBookIssueDate").ToString.Split(".")(1) & "月" & dr("VBookIssueDate").ToString.Split(".")(2) & "日"
            Else
                vc.WorkStartDate = "  年  月  日"
            End If
            If Not TypeOf dr("CreateDate") Is DBNull Then
                vc.WorkEndDate = dr("CreateDate").ToString.Split(".")(0) & "年" & dr("CreateDate").ToString.Split(".")(1) & "月" & dr("CreateDate").ToString.Split(".")(2) & "日"
            Else
                vc.WorkEndDate = "  年  月  日"
            End If

            vc.VBookID = dr("VBookID").ToString()
            vc.VolunteerID = dr("VolunteerID").ToString()
            vc.WorkTotalHour = dr("WorkHour").ToString()

            vc.Index = RowCount + 2

            vcList.Add(vc)

            ' i = i + 1
            RowCount = RowCount + 1
            If Not TypeOf (dr("OrganizationName")) Is DBNull Then
                prevVOrganizationName = dr("OrganizationName")
            Else
                prevVOrganizationName = ""
            End If

        Next

        Dim fileName As String = "VHonerCertList.doc"
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName)

        Dim velocity As New VelocityEngine
        Dim props As New Commons.Collections.ExtendedProperties

        'fix bug
        props.AddProperty("file.resource.loader.path", Server.MapPath("~\App_Data"))
        props.AddProperty("input.encoding", "utf-8")
        props.AddProperty("output.encoding", "utf-8")
        velocity.Init(props)

        Dim template As Template = velocity.GetTemplate("榮譽卡申請表 v01.xml")

        Dim context As New VelocityContext

        Dim approveDate As Date = Date.Now
        context.Put("ApproveDate", approveDate.Date.ToString("yyyy年MM月dd日"))
        context.Put("HonerCertList", vcList)
        context.Put("User", clsAuth.GetUserID())
        context.Put("DownloadDate", Today.Year.ToString() & "-" & Today.Month.ToString() & "-" & Today.Day.ToString() & "T" & Now.Hour.ToString() & ":" & Now.Minute.ToString() & ":" & Now.Second.ToString() & "Z")
        context.Put("IP", MyObj.getIP())
        Dim writer As New IO.StringWriter

        template.Merge(context, writer)

        Response.Write(writer.GetStringBuilder().ToString())

        Response.End()
    End Sub

    Private Function GetPhoto(ByVal photoFileName As String) As String
        'Dim photoPath As String = Me.photoBasePath + "\" + Integer.Parse(vbookID).ToString() + ".png"
        Dim photoPath As String = Me.photoBasePath + "\" + photoFileName

        'Dim photo As System.Drawing.Image = System.Drawing.Image.FromFile("a")
        'MyObj.WriteLog(photoPath)
        Try
            Using s As New BinaryReader(New FileStream(photoPath, FileMode.Open))
                Dim b() As Byte = s.ReadBytes(s.BaseStream.Length)

                Return Convert.ToBase64String(b)
            End Using
        Catch ex As System.Exception
            MyObj.WriteErrorLog(ex.Message)
            Return ""
        End Try
    End Function

    Private ReadOnly Property photoBasePath() As String
        Get
            If ViewState("photoBasePath") Is Nothing Then
                ViewState("photoBasePath") = Server.MapPath("~\Downloads\VBookPhoto")
            End If

            Return ViewState("photoBasePath")
        End Get
    End Property

    Public Function CancelHonortCert(ByVal rowIndex As Integer) As Boolean
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Dim key As DataKey = Me.gv.DataKeys(rowIndex)

        Using scope As New Transactions.TransactionScope
            sql.AppendFormat("update HonorCertApplication set Status='RJ' ")
            sql.AppendFormat("where ApplicationID = {0} ", key("ApplicationID"))

            dat.AccData(sql)

            scope.Complete()
        End Using

        Return True
    End Function

    Public ReadOnly Property ApplicationID() As String
        Get
            Return Me.gv.SelectedDataKey("ApplicationID")
        End Get
    End Property

    Public Class HonerCertList
        Private NoField As String
        Private PhotoPathField As String
        Private VolunteerNameField As String
        Private BirthdayField As String
        Private WorkStartDateField As String
        Private WorkEndDateField As String
        Private VBookIDField As String
        Private VolunteerIDField As String
        Private WorkTotalHourField As String
        Private VOrganizationNameField As String
        Private IndexField As Integer
        Private VSpaceField As String
        Public Property VSpace() As String
            Get
                Return Me.VSpaceField
            End Get
            Set(ByVal value As String)
                Me.VSpaceField = value
            End Set
        End Property
        Public Property VOrganizationName() As String
            Get
                Return Me.VOrganizationNameField
            End Get
            Set(ByVal value As String)
                Me.VOrganizationNameField = value
            End Set
        End Property
        Public Property Index() As Integer
            Get
                Return Me.IndexField
            End Get
            Set(ByVal value As Integer)
                Me.IndexField = value
            End Set
        End Property

        Public Property No() As String
            Get
                Return Me.NoField
            End Get
            Set(ByVal value As String)
                Me.NoField = value
            End Set
        End Property

        Public Property PhotoPath() As String
            Get
                Return Me.PhotoPathField
            End Get
            Set(ByVal value As String)
                Me.PhotoPathField = value
            End Set
        End Property

        Public Property VolunteerName() As String
            Get
                Return Me.VolunteerNameField
            End Get
            Set(ByVal value As String)
                Me.VolunteerNameField = value
            End Set
        End Property

        Public Property Birthday() As String
            Get
                Return Me.BirthdayField
            End Get
            Set(ByVal value As String)
                Me.BirthdayField = value
            End Set
        End Property

        Public Property WorkStartDate() As String
            Get
                Return Me.WorkStartDateField
            End Get
            Set(ByVal value As String)
                Me.WorkStartDateField = value
            End Set
        End Property

        Public Property WorkEndDate() As String
            Get
                Return Me.WorkEndDateField
            End Get
            Set(ByVal value As String)
                Me.WorkEndDateField = value
            End Set
        End Property

        Public Property VBookID() As String
            Get
                Return Me.VBookIDField
            End Get
            Set(ByVal value As String)
                Me.VBookIDField = value
            End Set
        End Property

        Public Property VolunteerID() As String
            Get
                Return Me.VolunteerIDField
            End Get
            Set(ByVal value As String)
                Me.VolunteerIDField = value
            End Set
        End Property

        Public Property WorkTotalHour() As String
            Get
                Return Me.WorkTotalHourField
            End Get
            Set(ByVal value As String)
                Me.WorkTotalHourField = value
            End Set
        End Property
    End Class
    Public Property IsVisible() As Boolean
        Get
            If ViewState("IsVisible") Is Nothing Then
                ViewState("IsVisible") = True
            End If
            Return ViewState("IsVisible")
        End Get
        Set(ByVal value As Boolean)
            ViewState("IsVisible") = value
        End Set
    End Property

    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
    Public Event SelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)
End Class